<template>
    <view>
        <view class="">
            <!-- confirm-type="search"  @confirm="doSearch" 把点击事件改为回车点击 -->
            <uni-easyinput v-model="keyword" placeholder="请输入商品名称" confirm-type="search"
                @confirm="doSearch"></uni-easyinput>
        </view>
        <view class="hxfx1" style="width: 95%;margin: auto;color:darkgrey ; margin-top: 20rpx;">
            <view class="">历史搜索</view>
            <view class="" @click="qingko">清空历史搜索</view>
        </view>
        <!-- 搜索渲染数据 -->
        <view class="y" style="width: 90%;margin: auto;margin-top: 50rpx;">
            <view class="x" v-for="(item,index) in sosuo" :key="index" style="height:200rpx;">
                <view style="width: 160rpx">
                    <image :src="item.picUrl" mode="" style="width: 160rpx;height: 160rpx;"></image>
                </view>
                <view class="zxfx" style="height: 80%;">
                    <view class="" style="color: #5a5a5a;font-size: 28rpx;">
                        <view class="">
                            {{item.name}}
                        </view>
                        <view class="">
                            {{item.brief}}
                        </view>
                    </view>
                    <view>
                        <span>
                            <span style="font-size: 25rpx;">￥</span>
                            <span>{{item.retailPrice}}</span>
                        </span>
                        <span style="font-size: 25rpx;text-decoration: line-through;
                        color: darkgrey;margin-left: 15rpx;">
                            ￥{{item.counterPrice}}
                        </span>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                sosuo: [], //搜索到的数据存储
                keyword: '',
            }
        },
        onLoad() {

        },
        methods: {
            doSearch() {
                console.log("点击了")
                uni.request({
                    url: 'http://47.91.230.137:8086/wx/goods/list',
                    method: "GET",
                    //传递必填字段
                    data: {
                        "keyword": this.keyword
                    },
                    success: (res) => {
                        // console.log(res)
                        const data = res.data
                        if (data.errmsg == '成功') {
                            this.sosuo = res.data.data.list;
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: data.errno,
                            })
                        }
                    }
                })
            },
            qingko() {
                uni.showModal({
                    title: '是否清空历史记录'
                })
            }
        }
    }
</script>

<style>

</style>